//
var service = new Vue({
	el:'#service',
	methods:{
		GetProjectDetail(projectid){
			example.GetProjectDetail(projectid)
			.then(resp => {
				vueData.projectdetail = resp.data.Data
	  			vueData.Montype = {text:resp.data.Data.ProjectInfo.ProjectTypeName}
			}).catch(err => {            
				console.log('请求失败'+err)
			});
		},
		LoadTag(projectid){
			example.LoadTag(projectid)
			.then(resp => {
	  			for(var i =0;i<resp.data.Data[0].items.length;i++){
	  				let tag = resp.data.Data[0].items[i]
	  				vueData.TagIds.push({text:tag.Name,value:tag.Id})
	  			}
	  		}).catch(err => {            
	  			console.log('请求失败'+err)
	  		});
		},
		LoadMethod(tag){
			example.LoadMethod(tag)
			.then(resp => {
				vueData.MethodIds = resp.data.Data
			}).catch(err => {            
				console.log('请求失败')
			});
		},
		planuserInit(){
			var _this = vueData
			var FormFlows =JSON.parse(_this.SampForm.FormFlows)
			console.log(FormFlows)
			let SamplingUserId = _this.SampForm.SamplingUserId.split(',')
			SamplingUserId.forEach(function(item){
				_this.SamplingUserList.forEach(function(ite){
					if(item==ite.Id){
						_this.SamplingUserSele.push(ite)
					}
				})
			})
			
			let SendUserId = FormFlows[0].FlowUserIds.split(',')
			SendUserId.forEach(function(item,index){
				_this.SamplingUserList.forEach(function(ite){
					if(item==ite.Id){
						_this.SendUserSele.push(ite)
					}
				})
			})
			
			let checkauditUserId = FormFlows[1].FlowUserIds.split(',')
			checkauditUserId.forEach(function(item,index){
				_this.checkauditUserList.forEach(function(ite){
					if(item==ite.Id){
						_this.checkauditUserSele.push(ite)
					}
				})
			})
			
			let verifyUserId = FormFlows[2].FlowUserIds.split(',')
			verifyUserId.forEach(function(item,index){
				_this.verifyUserList.forEach(function(ite){
					if(item==ite.Id){
						_this.verifyUserSele.push(ite)
					}
				})
			})
			
		},
		GetSampDetail(sampId,flowId,isCheck){
			example.GetSampDetail(sampId,flowId,isCheck)
			.then(resp => {
					var _this = vueData
					_this.sampDetail = resp.data.Data.Group
					console.log(resp.data.Data);
					_this.SampForm = resp.data.Data.Samp.SampForm
					console.log(_this.SampForm);
					_this.PrivateData = JSON.parse(_this.SampForm.PrivateData) 
					_this.SceneData = resp.data.Data.SencData
					_this.standData = resp.data.Data.Samp.SampForm.SamplingFormStands
					_this.FormFlows = JSON.parse(resp.data.Data.Samp.SampForm.FormFlows)
					service.GetAllAddressForSamp('',3,_this.SampForm.TagId,_this.projectid)
					this.sampdetailExt()
					resp.data.Data.Samp.HasFile.forEach(function(item){
						_this.fileList.push({
							url:"http://localhost:53239"+item.FilePath,
							Id:item.Id,
							file:{name:item.FileName}
						})
					})
					this.loadmethod()
					this.planuserInit()
				}).catch(err => {            
					console.log(err)
				});
		},
		loadmethod(){
			var _this = vueData
			_this.SceneData.forEach(function(item,index){
				axios.get(example.requestpath+'/api/Project/GetMethodsByIds',{
					 params:{
						 monIds:item.q[0].MonitemId
						},
						headers:{token:_this.token}
					 }).then(resp => {
						 _this.sceneMethod.push(resp.data.Data)
					 }).catch(err => {            
						console.log(err.message)
					 });
			})
		}
		,
		sampdetailExt(){
			var _this = vueData
			for(let i =0;i<_this.sampDetail.length;i++){
				var samps=[];
				var sampsence=[];
				_this.sampDetail[i].Mons.forEach(function(item,index){
					if(item.IsSence){
						sampsence.push(item)
					}else{
						samps.push(item)
					}
				})
				Vue.set(_this.sampDetail[i],"sampling",samps)
				Vue.set(_this.sampDetail[i],"samplingsence",sampsence)
			}
		},
		GetPlanUsers(projectid){
			example.GetPlanUsers(projectid)
			.then(resp => {
				vueData.SamplingUserList = resp.data.Data
			}).catch(err => {            
				console.log(err.message)
			});
		},
		GetUsersbyCode(rightCode){
			example.GetUsersbyCode(rightCode)
			.then(resp => {
				vueData.checkauditUserList = resp.data.Data
			}).catch(err => {            
				console.log(err.message)
			});
		},
		GetUsersbyCodev(rightCode){
			example.GetUsersbyCode(rightCode)
			.then(resp => {
				vueData.verifyUserList = resp.data.Data
			}).catch(err => {            
				console.log(err.message)
			});
		},
		GetunitAll(){
			example.GetunitAll()
			.then(resp => {
				vueData.unitAll = resp.data.Data
			}).catch(err => {            
				console.log(err.message)
			});
		},
		GetAllAddressForSamp(name,projectType,grouId,projectId){
			example.GetAllAddressForSamp(name,projectType,grouId,projectId)
			.then(resp => {
				this.addresses = []
				for(var i =0;i<resp.data.Data.length;i++){
					let ads = resp.data.Data[i]
					vueData.addresses.push({text:ads.Name,value:ads.Id})
				}
			}).catch(err => {            
				console.log(err.message)
			});
		},
		samplinginfoInit(){
			example.samplingInfoInit()
		},
		GetMonsByTagId(tagid){
			example.GetMonsByTagId(tagid)
			.then(resp => {
				example .mons_all = resp.data.Data
				example .mons_all_search = example .mons_all
			}).catch(err => {            
				console.log(err.message)
			});
		},
		SaveSamp(saveresult){
			example.SaveSamp(saveresult)
			.then(resp=>{
				console.log(resp.data)
			}).catch(err=>{
				console.log(err)
			})
		},
		GetSamplingImg(SampId){
			if(SampId.length!=36){
				alert("请先保存！！")
			}else{
				example.GetSamplingImg(SampId)
				.then(resp => {
					vueData.projectPDF = resp.data.Data;
				}).catch(err => {            
					console.log(err);
				});
			}
		},
		GetDevices(id,page,rows){//如果有id则只传id 如果没有id 则需要全参 ("",page,rows)
			if(id.length==0){
				//没有选择方法时
				example.GetDeviceForLayGrid(page,rows).then(resp=>{
					let data = resp.data.Data.data;
					vueData.allDev = data;
					console.log(resp)
				}).catch(err=>{
					console.log(err);
				});
			}else{
				//选择了方法时
				example.GetDevicesByMothodIds(id)
				.then(resp=>{
					let data = resp.data.Data.data;//**
					if(data.length==0){
						example.GetDeviceForLayGrid(page,rows).then(resp=>{
							vueData.allDev = resp.data.Data.data;
						console.log(resp)
						}).catch(err=>{
							console.log(err);
						});
					}
					vueData.allDev = resp.data.Data.data;
					console.log(vueData.allDev)
				}).catch(err=>{
					console.log(err);
				});
			}
		},
		async UploadFile(file){
			await example.UploadFile(file)
			.then(async resp=> {
				await vueData.UploadFiles.push(resp.data.Data);
			}).catch(err=>{
				console.log(err);
			});
		}
	},
})